import Vue from "vue";
import VueRouter from "vue-router";
import HomeView from "../views/HomeView.vue";
import LoginView from "../views/Login.vue";
//路由懒加载
const RegView = () => import("../views/RegView.vue");
const NotFound = () => import("../views/NotFound.vue");
const HomeIndex = () => import("../views/index/IndexView.vue");
const TestView = () => import("../views/test/TestView.vue");
const StartView = () => import("../views/start/StartView.vue");
const TestPaperView = () => import("../views/testPaper/TestPaper.vue");
const AnswerView = () => import("../views/answer/AnswerView.vue");
const EndView = () => import("../views/end/EndView.vue");
const AnalysisView = () => import("../views/analysis/AnalysisView.vue");
const WrongView = () => import("../views/wrong/WrongView.vue");
const CollectionView = () => import("../views/collection/CollectionView.vue");

Vue.use(VueRouter);

const routes = [
  //路由重定向
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    name: "LoginView",
    component: LoginView,
  },
  {
    path: "/reg",
    name: "RegView",
    component: RegView,
  },
  {
    path: "/start",
    name: "StartView",
    component: StartView,
  },
  {
    path: "/testPaper",
    name: "TestPaperView",
    component: TestPaperView,
  },
  {
    path: "/answer",
    name: "AnswerView",
    component: AnswerView,
  },
  {
    path: "/end",
    name: "EndView",
    component: EndView,
  },
  {
    path: "/analysis",
    name: "AnalysisView",
    component: AnalysisView,
  },
  {
    path: "/wrong",
    name: "WrongView",
    component: WrongView,
  },
  {
    path: "/collection",
    name: "CollectionView",
    component: CollectionView,
  },
  {
    path: "/home",
    name: "HomeView",
    component: HomeView,
    // 首页的子路由
    children: [
      {
        // 子路由的 path 不需要斜杠“/”
        path: "index",
        name: "index",
        component: HomeIndex,
      },

      {
        path: "test",
        name: "test",
        component: TestView,
      },
    ],
  },
  {
    path: "*",
    name: "NotFound",
    component: NotFound,
  },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   // component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
